package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 关键字自动补全
     * api/search/albumInfo/completeSuggest/{keyword}
     * @param keyword
     * @return
     */
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword){
        List<String> list=searchService.completaSuggest(keyword);

        return Result.ok(list);
    }



    /**
     * 查询指定一级分类下热门排行专辑
     * api/search/albumInfo/channel/{category1Id}
     * @param category1Id
     * @return
     */
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> channel(@PathVariable Long category1Id) {

        List<Map<String, Object>> mapList=  searchService.channel(category1Id);
        return Result.ok(mapList);

    }

    /**
     * 专辑关键字检索
     * api/search/albumInfo
     *
     * @param query
     * @return
     */
    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery query) {

        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(query);

        return Result.ok(albumSearchResponseVo);
    }


    /**
     * 专辑下架
     * api/search/albumInfo/lowerAlbum/{albumId}
     *
     * @param albumId
     * @return
     */
    @GetMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId) {

        searchService.lowerAlbum(albumId);

        return Result.ok();
    }


    /**
     * 专辑上架
     * api/search/albumInfo/upperAlbum/{albumId}
     *
     * @param albumId
     * @return
     */
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        searchService.upperAlbum(albumId);


        return Result.ok();
    }
}

